import java.util.Scanner;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/8 9:18
 * @Copyright 博为峰
 */
public class StuMg02 {
    public static int index = 0;

    public static boolean login(Scanner scanner) {
        System.out.println("请输入用户名");
        String name = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        if (name.equals("admin") && password.equals("123456")) {
            System.out.println("欢迎使用学生管理系统");
            return true;
        } else {
            System.out.println("用户名或密码错误!!!");
            return false;
        }
    }

    //ctrl + shift + ↓
    public static void main(String[] args) {
        System.out.println("1.登录");
        System.out.println("2.退出");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        switch (s) {
            case "1":
                do {
                    if (login(scanner)) break;
                } while (true);
                String[][] stus = new String[100][3];
                boolean isSecExit = false;
                do {
                    showMenu();
                    String secChoice = scanner.nextLine();
                    switch (secChoice) {
                        case "1":
                            addStu(scanner, stus);
                            break;
                        case "2":
                            updateStu(scanner, stus);
                        case "3":
                            deleteStu(scanner,stus);
                        case "4":
                            listStu(stus);
                            break;
                        case "5":
                            isSecExit = true;
                           break;
                        default:
                            System.out.println("请输入相应的功能");
                    }
                } while (!isSecExit);
            case "2":
                System.out.println("谢谢使用");
                break;
            default:
                System.out.println("请选择登录或退!!!");
        }
    }

    public static void deleteStu(Scanner scanner, String[][] stus) {
        System.out.println("请输入要删除的用户姓名");
        String name = scanner.nextLine();
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i][0].equals(name)) {
                stus[i] = null;
                break;
            }
        }
    }

    public static void listStu(String[][] stus) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i][0] != null) {
                for (int i1 = 0; i1 < stus[i].length; i1++) {
                    System.out.println(stus[i][i1]);
                }
            }
        }
    }

    public static void addStu(Scanner scanner, String[][] stus) {
        String[] stu = new String[3];
        System.out.println("请输入用户名");
        stu[0] = scanner.nextLine();
        System.out.println("请输入年龄");
        stu[1] = scanner.nextLine();
        System.out.println("请输入性别");
        stu[2] = scanner.nextLine();
        stus[index] = stu;
        index++;
    }

    public static void updateStu(Scanner scanner, String[][] stus) {
        System.out.println("请输入要修改的用户的姓名");
        String name = scanner.nextLine();
        System.out.println("请输入要修改的用户的年龄");
        String age = scanner.nextLine();
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i][0].equals(name)) {
                stus[i][1] = age;
                break;
            }
        }
    }

    public static void showMenu() {
        System.out.println("1.新增");
        System.out.println("2.修改");
        System.out.println("3.删除");
        System.out.println("4.查询");
        System.out.println("5.退出");
    }
}
